import imaplib,rfc822
from email.header import decode_header
hostAddr="luchao62@gmail.com"
mail = imaplib.IMAP4_SSL('imap.gmail.com', 993) 
mail.login(hostAddr,"198562")
folders = [folder.split(' "/" ')[1][1:-1] for folder in mail.list('/')[1]]
#print folders
mail.select("[Gmail]/All Mail")
typ, data = mail.search(None, 'ALL')
for num in data[0].split():
	typ_from, data_from = mail.fetch(num, '(BODY[HEADER.FIELDS (FROM TO CC BC)])')
	print  {num: data_from[0][1]}
mail.close()
mail.logout()
